package com.zx.screener.service.userCenter.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import com.zx.screener.service.userCenter.model.Manager;
import com.zx.screener.service.userCenter.service.ManagerService;

/**
 * @author zhanghaijie
 * 
 */
public class ManagerServiceImpl implements ManagerService {

	private MongoTemplate mongoTemplate;

	@Override
	public void createManager(Manager manager) {
		// TODO Auto-generated method stub
		mongoTemplate.insert(manager);

	}

	@Override
	public Manager login(String username, String password) {
		Manager manager = mongoTemplate.findOne(new Query(new Criteria(
				"username").is(username)), Manager.class);
		if (null != manager
				&& StringUtils.equals(manager.getPassword(), password)) {
			return manager;
		}
		return null;
	}

	public void setMongoTemplate(MongoTemplate mongoTemplate) {
		this.mongoTemplate = mongoTemplate;
	}

}
